package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {


    /**
     * @param id:
     * @return Integer
     * @description 根据分类id统计数量
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * @param setmeal:
     * @return void
     * @description TODO
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * @param setmealPageQueryDTO:
     * @return Page<SetmealVO>
     * @description 套餐分页查询
     */
     /*select s.* , c.name as categoryName from setmeal as s left outer join category c on s.category_id = c.id
    order by s.create_time desc*/
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * @param id:
     * @return Setmeal
     * @description 通过套餐id查找套餐
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);

    /**
     * @param id:
     * @return void
     * @description 根据套餐id删除套餐
     */
    @Select("delete from setmeal where id=#{id}")
    void deleteById(Long id);


    /**
     * @param setmeal:
     * @return void
     * @description 修改套餐
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * @param id:
     * @return List<Setmeal>
     * @description 根据菜品id查询与之关联的套餐
     */
    @Select(" select * from setmeal where id in(select setmeal_id from setmeal_dish where dish_id=#{id})")
    List<Setmeal> getByDishId(Long id);

    /**
     * @param setmeal:
     * @return List<Setmeal>
     * @description 动态条件查询套餐
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * @param setmealId:
     * @return List<DishItemVO>
     * @description 根据套餐id查询菜品选项
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
